
var minWindow = function(s: string, t: string): string {
    if(s === null || s.length < t.length || s.length === 0) {
        return "";
    }    

    var map = new Map<string, number>()
    for(var c of t) {
        if ( map.has(c)) map.set(c, map.get(c) + 1)
        else map.set(c, 1)
    }

    var left = 0;
    var minLeft = 0;
    var minLen = s.length + 1;
    var count = 0;

    for(var right = 0; right < s.length; right++) {
        var c = s[right];
        if ( map.has(c)) {
            map.set(c, map.get(c) - 1);
            if(map.get(c) >= 0) {
                count++;
            }

            while(count == t.length) {
                if(right - left + 1 < minLen){
                    minLeft = left;
                    minLen = right - left + 1;
                }
                var startChar = s[left];
                if( map.has( startChar)){
                    map.set( startChar, map.get( startChar) + 1);
                    if(map.get(startChar) > 0) {
                        count --;
                    }
                } 
                left ++ ;
            }            
        }
    }

    if(minLen > s.length)  
    {  
        return "";  
    }  
    
    return s.substring(minLeft,minLeft+minLen);
};

//var answer76 = minWindow( "ADOBECODEBANC", "ABC");
console.assert( minWindow( "ADOBECODEBANC", "ABC") === "BANC");

console.log('The END!')